﻿using System;
using System.Linq;

namespace USERS.CYT369.COM.DAL
{
    public class SystemService : USERS.CYT369.COM.DAL.DbContexts.UserBaseService<SystemService>
    {
        public SystemService() { }

        public IQueryable<USERS.CYT369.COM.MODELS.App> GetAllApps()
        {
            return base.Get<USERS.CYT369.COM.MODELS.App>(c => c.Enable == true);
        }

        public USERS.CYT369.COM.MODELS.App GetApp(string appId)
        {
            return base.GetOne<USERS.CYT369.COM.MODELS.App>(c => c.AppID == appId);
        }

        public USERS.CYT369.COM.MODELS.App GetApp(string appId, string appKey)
        {
            return base.GetOne<USERS.CYT369.COM.MODELS.App>(c => c.AppID == appId && c.AppKey == appKey);
        }

        /// <summary>
        /// App是否启用
        /// </summary>
        /// <param name="appId"></param>
        /// <param name="appKey"></param>
        /// <returns></returns>
        public bool IsEnableApp(string appId, string appKey)
        {
            using (var db = this.UserCtx)
            {
                return db.Apps.Where(c => c.AppID == appId && c.AppKey == appKey && c.Enable == true).Count() > 0;
            }
        }

    }
}
